package mqtt;


import HslCommunication.Core.Types.OperateResultExOne;
import HslCommunication.MQTT.MqttHelper;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;


public class MqttTest {

    @Test
    public void TestMethod1( )
    {
        OperateResultExOne<byte[]> length = MqttHelper.CalculateLengthToMqttLength( 56 );
        Assertions.assertTrue( length.IsSuccess );
        Assertions.assertTrue( length.Content.length == 1 );
        Assertions.assertTrue( length.Content[0] == 56 );
    }

    @Test
    public void TestMethod2( )
    {
        OperateResultExOne<byte[]> length = MqttHelper.CalculateLengthToMqttLength( 1738 );
        Assertions.assertTrue( length.IsSuccess );
        Assertions.assertTrue( length.Content.length == 2 );
        Assertions.assertTrue( length.Content[0] == (byte) 0xCA );
        Assertions.assertTrue( length.Content[1] == 0x0D );
    }

    @Test
    public void TestMethod3( )
    {
        OperateResultExOne<byte[]> length = MqttHelper.CalculateLengthToMqttLength( 2097151 );
        Assertions.assertTrue( length.IsSuccess );
        Assertions.assertTrue( length.Content.length == 3 );
        Assertions.assertTrue( length.Content[0] == (byte)0xFF );
        Assertions.assertTrue( length.Content[1] == (byte)0xFF );
        Assertions.assertTrue( length.Content[2] == 0x7F );
    }

    @Test
    public void TestMethod4( )
    {
        OperateResultExOne<byte[]> length = MqttHelper.CalculateLengthToMqttLength( 268435455 );
        Assertions.assertTrue( length.IsSuccess );
        Assertions.assertTrue( length.Content.length == 4 );
        Assertions.assertTrue( length.Content[0] == (byte)0xFF );
        Assertions.assertTrue( length.Content[1] == (byte)0xFF );
        Assertions.assertTrue( length.Content[2] == (byte)0xFF );
        Assertions.assertTrue( length.Content[3] == 0x7F );
    }
}
